﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using l1cs.server.model.Instance;

namespace l1cs.server.serverpackets
{
    public class S_PetInventory : ServerBasePacket
    {
        private static Logger _log = Logger.getLogger( typeof( S_PetInventory ).FullName );
 
        private byte[] _byte = null;

        public S_PetInventory( L1PetInstance pet )
        {
            object[] itemList = pet.getInventory().getItems();

            writeC( Opcodes.S_OPCODE_SHOWRETRIEVELIST );
            writeD( pet.getId() );
            writeH( itemList.Length );
            writeC( 0x0b );
            foreach ( L1ItemInstance item in itemList )
            {
                if ( item != null )
                {
                    writeD( item.getId() );
                    writeC( 0x13 );
                    writeH( item.get_gfxid() );
                    writeC( item.getBless() );
                    writeD( item.getCount() );
                    writeC( item.isIdentified() ? 1 : 0 );
                    writeS( item.getViewName() );
                }
            }
            writeC( 0x0a );
        }

        override
        public byte[] getContent()
        {
            if ( _byte == null )
            {
                _byte = getBytes();
            }
            return _byte;
        }

        override
        public String getType()
        {
            return "[S] S_PetInventory";
        }
    }
}